<template>
  <div class="page-main"  v-title data-title="科技成果交易表">
    <home-nav :userData="userinfo"></home-nav>
    <div class="banner"><span>科技成果交易表</span></div>
    <div class="container">
      <div class="container-bg">
        <div class="header">
          <a-row type="flex" justify="space-between" align="middle">
            <a-col :xl="{ span: 11 }" :lg="{ span: 11 }">
              <a-button class="hte-btn add-btn" type="primary" icon="plus" @click="handAction('add')" v-has="'tcg:edit'">新建</a-button>
              <a-button class="hte-btn port-btn"  @click="handlePostExportXls('科技成果交易表')" v-has="'rcg:export'">导出</a-button>
              <a-button class="hte-btn" type="danger"  @click="handAction('del')" v-has="'tcg:edit'">删除</a-button>
              <a-button class="hte-btn" @click="handAction('refresh')">刷新</a-button>
            </a-col>            
            <a-col :xl="{ span: 9 }" :lg="{ span: 13 }" class="input-ground">
              <a-input-group compact>
                <a-select v-model="queryParam.searchField">
                  <a-select-option value="1"> 项目编号 </a-select-option>
                  <a-select-option value="2"> 项目名称 </a-select-option>
                </a-select>
                <a-input-search v-model="queryParam.keyword" @search="doSearch" allowClear placeholder="请输入关键词检索" />
              </a-input-group>
              <a-button class="hte-btn del-btn" @click="visibleModel=true">高级查询</a-button>
            </a-col>
          </a-row>
        </div>
        <div class="content">
          <a-table
            class="hte-table-content"
            :scroll="{ x: true }"          
            :columns="columns"
            :data-source="dataSource"
            :pagination="ipagination"
            :loading="loading"
            :row-selection="{ selectedRowKeys: selectedRowKeys, onChange: onSelectChange }"
            rowKey="id"
            size="middle"
            @change="handleTableChange"
          >
            <template slot="ellipsis" slot-scope="text">
              <span :title="text">{{text | ellipsis(15)}}</span>
            </template>
            <template slot="designerName" slot-scope="text, record">
              <span>{{ record.designArrange=='1'?record.designerName:record.designSupplier }}</span>
            </template>
            <template slot="cgNo" slot-scope="text, record">
              <span style="color: blue;cursor: pointer;" @click="gotoDetail(record.id, record.projectBuildId)">{{ text }}</span>
            </template>
          </a-table>
        </div>
      </div>
    </div>
    <a-back-top class="backtodom" />
    <a-modal
      v-model="visibleModel"
      width="70vw"
      :bodyStyle="{ padding: '10px' }"
      title="高级搜索"
      @ok="callBackResult"
    >      
      <advanced-search :dataForm.sync="queryParam" ref="advanced"></advanced-search>
      <template slot="footer">
        <div class="footer-line">
          <a-button  @click="closeResulte">关 闭</a-button>
          <a-button  @click="resetResulte">重 置</a-button>
          <a-button type="primary" @click="callBackResult">确 定</a-button>
        </div>
      </template>
    </a-modal>
  </div>
</template>
<script>
import Vue from 'vue'
import { getAction,postAction} from '@/api/manage'
import { JeecgListMixin } from '@/mixins/JeecgListSearchMixin'
import { USER_INFO } from '@/store/mutation-types'
import {filterHasPermission} from '@/utils/hasPermission'
import { filterObj } from '@/utils/util';

export default {
  name: 'TechResultList',
  mixins: [JeecgListMixin],
  components: {
    HomeNav: () => import('@/components/layouts/HomeNav'),
    AdvancedSearch: () => import('./advancedSearch'),    
  },
  data() {
    return {
      userinfo: {
        info: this.$store.getters.userInfo,
        module: 'TechResultList',
      },
      currUser:Vue.ls.get(USER_INFO).username,
      columns:[
        {title: '项目状态',dataIndex: 'projectStatusName',width:70,align: 'center', ellipsis: true},
        {title: '项目编号',dataIndex: 'projectNo',width:120,align: 'center', ellipsis: true},
        {title: '项目名称',dataIndex: 'projectName',width:200,align: 'center', ellipsis: true, scopedSlots: { customRender: 'ellipsis' }},
        {title: '项目经理',dataIndex: 'projectManager',width:120,align: 'center', ellipsis: true, scopedSlots: { customRender: 'ellipsis' }},
        {title: '交易状态',dataIndex: 'statusName',width:70,align: 'center', ellipsis: true},
        {title: '成果交易单号',dataIndex: 'cgNo',width:120,align: 'center', ellipsis: true,scopedSlots: { customRender: 'cgNo' },},
        {title: '科技成果名称',dataIndex: 'cgName',width: 140,align: 'center', ellipsis: true,scopedSlots: { customRender: 'ellipsis' },},
        {title: '交易甲方公司（投资方）',dataIndex: 'cgCompany',width:120,align: 'center', ellipsis: true,scopedSlots: { customRender: 'ellipsis' }},
        {title: '交易乙方公司',dataIndex: 'pbCompany',width:120,align: 'center', ellipsis: true,scopedSlots: { customRender: 'ellipsis' }},
        {title: '交易价格(万)',dataIndex: 'tranPrice',width:120,align: 'center', ellipsis: true,},
        {title: '审核交易价格(万)',dataIndex: 'tranPriceAudit',width:120,align: 'center', ellipsis: true,},
        {title: 'HBK定价流程号',dataIndex: 'hbkNo',width:120,align: 'center', ellipsis: true,},
        {title: '甲方经营体（一级架构）',dataIndex: 'firstPartyDep',width:120,align: 'center', ellipsis: true,scopedSlots: { customRender: 'ellipsis' }},
        {title: '乙方经营体（一级架构）',dataIndex: 'secondPartyDep',width:120,align: 'center', ellipsis: true,scopedSlots: { customRender: 'ellipsis' }},
        {title: '交易类型',dataIndex: 'tranTypeName',width:120,align: 'center', ellipsis: true,},
        {title: '研发成本(万)',dataIndex: 'yfMoney',width:120,align: 'center', ellipsis: true,},
        {title: '项目资金成本(万)',dataIndex: 'zjMoney',width:120,align: 'center', ellipsis: true,},
        {title: '效益贡献值',dataIndex: 'gxValueName',width:120,align: 'center', ellipsis: true,},
        {title: '技术收益期限',dataIndex: 'techProfitTerm',width:120,align: 'center', ellipsis: true,},
       
      ],      
      url: {
        list: "/projectBuild/ProjectBuildCg/list",
        deleteBatch: "/projectBuild/ProjectBuildCg/deleteBatch",
        // delBatch:'/hteLibMediaOrder/delBatch',
        exportXlsUrl:'/projectBuild/ProjectBuildCg/exportXls'
      },
      // 高级查询
      visibleModel: false,
      form: {},
    }
  },
  mounted() {
    this.queryParam={
      keyword:'',
      searchField:'1',
      projectNo:'', // 项目编号
      projectName:'', // 项目名称
    };
    this.loadData(1)
  },
  methods: {
    doSearch() {
      this.loadData(1)
    },
    /**
     * 高级搜索 
     */
    callBackResult(){
      this.visibleModel = false;
      if(Object.keys(this.queryParam).length == 0){
        return
      }
      this.queryParam.advancedSearch = true;
      this.loadData(1);

    },
    closeResulte(){
      this.visibleModel = false;
      this.resetResulte();
    },
    resetResulte(){
      this.$refs.advanced.resetForm()
    },
    /**
     *  查询
     */
    loadData(arg){
      if (arg === 1) {
        this.ipagination.current = 1;
      }
      this.loading = true
      getAction(this.url.list, this.getQueryParams()).then((res) => {
        if (res.code == 200 && res.result) {
          this.ipagination.total = res.result.total          
          this.dataSource = res.result.records
          this.loading = false
        } else {
          this.$message.warning('数据加载失败:' + res.message)
          this.loading = false
        }
      })
    },
    getQueryParams() {
      //获取查询条件
      let param = this.queryParam;
      param.pageNo = this.ipagination.current;
      param.pageSize = this.ipagination.pageSize;
      if(!this.queryParam.advancedSearch){
        if(this.queryParam.searchField == '1'){
          this.queryParam.projectNo = this.queryParam.keyword
          this.queryParam.projectName = ''
        }else{
          this.queryParam.projectName = this.queryParam.keyword
          this.queryParam.projectNo = ''
        }
      }else{
        this.queryParam.searchField = '1'
        this.queryParam.keyword = ''
      }
      this.queryParam.advancedSearch = false
      return filterObj(param);
    },
    /**
     * 操作 
     */
    handAction(type){
      if(type == 'add'){
        // 新增
        let routeUrl = this.$router.resolve({
          path: '/techResult/addOrder',
          query:{createType:2},
        });
        window.open(routeUrl.href, '_blank');
      }
      if(type == 'del'){
        const that = this;
        that.batchDel()
        // 删除，可多选
        // if(this.selectedRowKeys.length == 0){
        //   this.$message.warning('请选择至少一条数据！');
        //   return;
        // }
        // const flag = this.selectionRows.some(item=>{
        //   return item.projectStatus != 1
        // })
        // if(flag){
        //   this.$message.warning('已选订单状态不允许删除，只可删除状态为创建中的订单');
        //   return;
        // }
        // for(let i=0;i<this.selectionRows.length;i++){
        //   let row=this.selectionRows[i];
        //   if(row.processInstanceId&&row.applyUserId != that.currUser){
        //     this.$message.warning('订单【'+row.orderNo+'】已发起流程，需申请人自己才能删除');
        //     return;
        //   }
        // }
        // this.$confirm({
        //   title: '确认删除',
        //   content: '请确认是否删除此订单?',
        //   onOk: function() {
        //     postAction(that.url.delBatch, that.selectedRowKeys).then((res) => {
        //       if (res.code == 200) {
        //         that.$message.success('删除成功')
        //         that.loadData();
        //       } else {
        //         that.$message.warning('删除失败:' + res.message)
        //       }
        //     })            
        //   }
        // });
        // console.log(that.selectedRowKeys)
      }
      if(type == 'refresh'){
        this.loadData();
      }
    },
    gotoDetail(id, pId){
      let routeUrl = this.$router.resolve({
        path: '/techResult/addOrder',
        query: {id:id}
      });
      window.open(routeUrl.href, '_blank');
    },
  },
}
</script>

<style lang="less" scoped>
@import '~@assets/less/hte-main.less';
.page-main {
  .banner {    
    background-image: url(../../../assets/contract-top.png);
  }
  .container {padding: 0 125px 80px;
    .container-bg{
      background-color: #fff;padding: 25px;
      .content{margin-top: 22px;}
      /deep/ .ant-pagination{
        background-color: #f5f5f5;
        padding: 10px 15px;
      }
    }
    .succfont {
      color: @font-color-succ;
    }  
    .header .input-ground{align-items: flex-start;}  
  }
  .hte-btn{min-width: auto;padding: 0 11px;margin-bottom: 5px;}
}
</style>